﻿namespace Hippo.Agent.Lib
{
    using System;
    using System.Threading;
    using Autofac;
    using ControlService;
    using Runner;
    using Framework.Model;
    using Hippo.Common;

    public class ControlServerCallback : HippoConsoleControlCallback
    {
        public Guid StartTest(RunSpecification specification)
        {
            var testRunIdentifier = Guid.NewGuid();

            for (int i = 0; i < specification.Scenarios[0].Repeat; i++)
            {
                ThreadPool.QueueUserWorkItem(args =>
                    {
                        var scriptHost = new ScriptHost();
                        var test = scriptHost.GetTestClass(specification);
                        var result = new LatencyTestRunner().Execute(test);

                        ContainerFactory.Current.Resolve<ConsoleClient>()
                            .RegisterTestResult(result);
                    });
            }

            return testRunIdentifier;
        }

        public void StopTest()
        {
            //throw new NotImplementedException();
        }
    }
}
